package kim.artemis.rpc.core.protocol.client;

import kim.artemis.rpc.core.common.exception.ArtemisException;
import kim.artemis.rpc.core.model.ArtemisRpcRequest;

/**
 * 客户端
 * @author Wq.
 */
public class ArtemisRpcClient {


    private volatile ArtemisRpcReferenceBean artemisRpcReferenceBean;


    public void init (ArtemisRpcReferenceBean artemisRpcReferenceBean) {
        this.artemisRpcReferenceBean = artemisRpcReferenceBean;
    }


    /**
     * 异步发送
     */
    public void asyncSend (String socketAddress, ArtemisRpcRequest artemisRpcRequest) throws Exception {
        ArtemisRpcClientSession clientSession = ArtemisRpcClientConnectionPool.getClientSessionPool(socketAddress, artemisRpcReferenceBean);
        try {
            clientSession.send(artemisRpcRequest);
        } catch (Exception e) {
            throw new ArtemisException(e);
        }
    }

}
